/*!
    \copyright  Copyright (c) 2023-2024 Qualcomm Technologies International, Ltd.
                All Rights Reserved.
                Qualcomm Technologies International, Ltd. Confidential and Proprietary.
    \file
    \ingroup    le_unicast_manager
    \brief      Audio context handling of the le unicast manager
*/

#ifdef INCLUDE_LE_AUDIO_UNICAST
#include "le_unicast_manager_private.h"
#include "le_unicast_manager_instance.h"
#include "pacs_audio_contexts.h"

void LeUnicastManager_UpdateAvailableAudioContexts(le_um_instance_t * inst, AudioContextType audio_context, bool claim)
{
#ifndef DISABLE_AUTO_PACS_UPDATE
    audio_contexts_config_t available_audio_contexts = {0};
    audio_contexts_config_t streaming_audio_contexts = {0};

    if (claim)
    {
        streaming_audio_contexts.sink = leUnicastManager_IsAnyAseEnabledForGivenDirection(inst, ASE_DIRECTION_AUDIO_SINK) ? audio_context : AUDIO_CONTEXT_TYPE_UNKNOWN;
        streaming_audio_contexts.source = leUnicastManager_IsAnyAseEnabledForGivenDirection(inst, ASE_DIRECTION_AUDIO_SOURCE) ? audio_context : AUDIO_CONTEXT_TYPE_UNKNOWN;

        available_audio_contexts.sink = (LeBapPacsUtilities_GetSinkAudioContextAvailability() & ~streaming_audio_contexts.sink);
        available_audio_contexts.source = (LeBapPacsUtilities_GetSourceAudioContextAvailability() & ~streaming_audio_contexts.source);
    }
    else
    {
        available_audio_contexts.sink = (LeBapPacsUtilities_GetSinkAudioContextAvailability() | audio_context);
        available_audio_contexts.source = (LeBapPacsUtilities_GetSourceAudioContextAvailability() | audio_context);
    }

    PacsAudioContexts_UpdateAvailableAudioContexts(available_audio_contexts);
#endif /* DISABLE_AUTO_PACS_UPDATE */
}
#endif
